package com.example.petproject.handler;

import com.example.petproject.entity.vo.ReturnVO;
import com.example.petproject.execption.BaseException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 包名称：com.example.petproject.hander
 * 类名称：CustomExceptionHandler
 * 类描述：自定义异常处理器
 * 创建人：@author DrinkMore-HotWater
 * 创建时间：2024年01月06日 11:11
 **/
//用于捕获异常并处理
@RestControllerAdvice
public class CustomExceptionHandler {


    private static final Logger log = LoggerFactory.getLogger(CustomExceptionHandler.class);

    @ExceptionHandler(value = BaseException.class)
    public ReturnVO<Void> handBaseException(BaseException e){
        log.error("统一的异常处理：{}",e.getMessage());
        return ReturnVO.error(e.getCode(),e.getMessage());
    }
}
